package cn.xny.txcc.mq;

import cn.xny.txcc.domain.MediaFile;
import cn.xny.txcc.service.IMediaFileService;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.apache.rocketmq.spring.annotation.MessageModel;



@Slf4j
@Component
@RocketMQMessageListener(
              consumerGroup = "service-consumer-media",
              topic = "media-topic",
               selectorExpression = "media-tags",
               messageModel = MessageModel.CLUSTERING
)
public class MediaFileConsumer implements RocketMQListener<String> {

    @Autowired
    private IMediaFileService mediaFileService;
    @Override
    public void onMessage(String message) {
        //从MQ里面获取到的消息
        /*
            1.把json字符串进行数据还原 MediaFile对象
         */
        MediaFile mediaFile = JSON.parseObject(message, MediaFile.class);

        //推送流方法
        mediaFileService.handleFile2m3u8(mediaFile);
    }
}
